import unittest
from cases.base_case import BaseCase
from page.index_page import IndexPage
from page.xitongbushu.xt_zzjg_page import OrganizationPage
from page.xitongbushu.xt_tjbm_page import AddDepartmentPage
from tools.sjqd_way import read_data_from_excel
from config.config import DATA_PATH
import os


class AddDepartment(BaseCase):
    # 第12条用例
    def test_tjbm_into(self):
        gr = IndexPage(self.driver)
        gr.click_geren_btn()
        # 进入组织架构
        zz = OrganizationPage(self.driver)
        zz.zzjg_into()
        # 进入添加部门
        zz.zzjg_tjbm()

        # 断言
        # 实例化
        dy = AddDepartmentPage(self.driver)
        text = '添加部门'
        self.assertIn(text,dy.tjbm_duanyan_into())

    # 第13条用例
    def test_tjbm_quxiao(self):
        gr = IndexPage(self.driver)
        gr.click_geren_btn()
        # 进入组织架构
        zz = OrganizationPage(self.driver)
        zz.zzjg_into()
        # 进入添加部门
        zz.zzjg_tjbm()
        # 点击取消
        # 实例化
        dy = AddDepartmentPage(self.driver)
        dy.tjbm_quxiao()

        # 断言
        # 确认
        text_bc = dy.tjbm_duanyan_quxiaotankuang()
        text = '报错'
        self.assertEqual(text,text_bc)

        # 第14条用例

    def test_tjbm_quanbushuru(self):
        # 引入数据
        datas = read_data_from_excel(os.path.join(DATA_PATH, 'datas.xls'), '添加部门')
        name, bmms = datas[0]
        gr = IndexPage(self.driver)
        gr.click_geren_btn()
        # 进入组织架构
        zz = OrganizationPage(self.driver)
        zz.zzjg_into()
        # 进入添加部门
        zz.zzjg_tjbm()
        # 实例化
        dy = AddDepartmentPage(self.driver)
        dy.tjbm_bmm(name)
        # 添加上级部门
        dy.tjbm_sjbm()
        # 输入描述
        dy.tjbm_bmms(bmms)
        # 确认
        dy.tjbm_queren()
        # 断言
        text = '添加部门成功'
        self.assertIn(text, dy.tjbm_duanyan_tianjia())



if __name__ == '__main__':
    unittest.main()

